<template>
  <div class>
    <el-table
      v-loading="state.loading"
      :data="state.tableData"
      header-cell-class-name="eltablebg"
      style="width: 100%;margin-bottom:30px"
    >
      <el-table-column
        prop="create_time"
        :label="$t('assets.time')"
      ></el-table-column>
      <el-table-column
        prop="currency_name"
        :label="$t('assets.currency')"
      ></el-table-column>
      <el-table-column prop="amount" :label="$t('assets.amount')">
        <template #default="r">{{ $currency(r.row.amount) }}</template>
      </el-table-column>
      <el-table-column
        prop="financial_type"
        :label="$t('assets.swipeDirection')"
      >
        <template #default="r">
          <span>{{ getFinancialtype(r.row.financial_type) }}</span>
        </template>
      </el-table-column>
      <template #empty>
        <Norecord />
      </template>
    </el-table>
    <Pagination
      :total="state.total"
      :size="state.listParam.limit"
      :current="state.curentPage"
      @currentchange="currentchange"
    />
  </div>
</template>

<script>
import { transferRecord } from "@/api/assets";
import { demotransferRecord } from "@/api/demo";
import UseSystemSetting from "@/commonapi/useSystemSetting";
import Pagination from "@/components/pagination/index.vue";
import Norecord from "@/components/noRecord/NoRecord.vue";

import { reactive, onMounted } from "vue";
import { useI18n } from "vue-i18n";
export default {
  name: "RecordHuazhuan",
  components: { Norecord, Pagination },
  setup() {
    const { t } = useI18n();
    const state = reactive({
      tableData: [],
      loading: false,
      total: 0,
      curentPage: 1,
      listParam: {
        page: 0,
        limit: 10,
      },
    });
    onMounted(() => {
      gettableData();
    });
    // 获取开关状态
    const { virtual_wallet } = UseSystemSetting();
    // 获取划转列表
    const gettableData = () => {
      state.loading = true;
      let setFun = virtual_wallet.value ? demotransferRecord : transferRecord;
      setFun(state.listParam)
        .then((res) => {
          state.loading = false;
          state.tableData = res.data.items;
          state.total = res.data.total;
        })
        .catch(() => {
          state.loading = false;
        });
    };
    // 获取提现状态文案
    const getFinancialtype = (status) => {
      switch (status) {
        case 1:
          return t("exchange.currencyToLegal");
        case 2:
          return t("exchange.currencyToLever");
        case 3:
          return t("exchange.legalToCurrency");
        case 4:
          return t("exchange.leverToCurrency");
        case 5:
          return t("assets.recharge");
        case 6:
          return t("assets.withdrawMoney");
        case 7:
          return t("exchange.buy");
        case 8:
          return t("exchange.sell");
        case 22:
          return t("exchange.currencyToSecond");
        case 23:
          return t("exchange.secondToCurrency");
        case 31:
          return t("exchange.currencyToFinancial");
        case 32:
          return t("exchange.financialToCurrency");
        case 53:
          return t("NFT.toNFT");
        case 54:
          return t("NFT.toExchange");
        case 2007:
          return t("exchange.currencyToStockSpot");
        case 2008:
          return t("exchange.stockSpotToCurrency");
        case 2013:
          return t("exchange.currencyToStockLever");
        case 2014:
          return t("exchange.stockLeverToCurrency");
        case 2015:
          return t("exchange.currencyToStockSecond");
        case 2016:
          return t("exchange.stockSecondToCurrency");
        case 2021:
          return t("exchange.stockSpotToStockLever");
        case 2022:
          return t("exchange.stockSpotToStockSecond");
        case 2023:
          return t("exchange.stockLeverToStockSpot");
        case 2024:
          return t("exchange.stockSecondToStockSpot");
        case 60002:
          return t("foreign.currencyToForex");
        case 60003:
          return t("foreign.forexToCurrency");

        case 70001:
          return t("exchange.fiatToLever");
        case 70002:
          return t("exchange.fiatToSecond");
        case 70003:
          return t("exchange.fiatToStock");
        case 70004:
          return t("exchange.fiatToStockLever");
        case 70005:
          return t("exchange.fiatToStockSecond");
        case 70006:
          return t("exchange.fiatToForeign");
        case 70007:
          return t("exchange.fiatToFinancial");
        case 70008:
          return t("exchange.fiatToNFT");
        case 70009:
          return t("exchange.leverToFiat");
        case 70010:
          return t("exchange.secondToFiat");
        case 70011:
          return t("exchange.stockToFiat");
        case 70012:
          return t("exchange.stockLeverToFiat");
        case 70013:
          return t("exchange.stockSecondToFiat");
        case 70014:
          return t("exchange.foreignToFiat");
        case 70015:
          return t("exchange.financialToFiat");
        case 70016:
          return t("exchange.NFTToFiat");
      }
    };
    // 分页
    const currentchange = (val) => {
      state.listParam.page = val;
      gettableData();
    };
    return {
      state,
      gettableData,
      currentchange,
      getFinancialtype,
    };
  },
};
</script>

<style scoped lang="less">
.jump {
  width: 44px;
  height: 20px;
  line-height: 20px;
  margin-inline-start: 10px;
}
.page {
  width: 20px;
  height: 20px;
}
</style>
